package com.yudaob2b.common.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 *
 * @author Kidd.Tan
 * @email 298023780@qq.com
 * @date 2018-02-08
 */
public class ABSResponse extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ABSResponse() {
        put("code", "200");
        put("msg", "ok");
        put("data", "");
    }

    public static ABSResponse error() {
        return error("500", "未知异常，请联系管理员");
    }

    public static ABSResponse error(String msg) {
        return error("500", msg);
    }

    public static ABSResponse error(String code, String msg) {
        ABSResponse r = new ABSResponse();
        r.put("code", code);
        r.put("msg", msg);
        r.put("data", "");
        return r;
    }

    public static ABSResponse ok(String msg) {
        ABSResponse r = new ABSResponse();
        r.put("msg", msg);
        return r;
    }

    public static ABSResponse ok(String msg, Object object) {
        ABSResponse r = new ABSResponse();
        r.put("msg", msg);
        r.put("data", object);
        return r;
    }

    public static ABSResponse ok(Object object) {
        ABSResponse r = new ABSResponse();
        r.put("data", object);
        return r;
    }

    public static ABSResponse ok(Map<String, Object> map) {
        ABSResponse r = new ABSResponse();
        r.putAll(map);
        return r;
    }

    public static ABSResponse ok() {
        return new ABSResponse();
    }

    @Override
    public ABSResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
